from AccessControl.Role import RoleManager
from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager
from Globals import InitializeClass
from Globals import DTMLFile, HTMLFile
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.ZCatalog.CatalogPathAwareness import CatalogAware
from Acquisition import Implicit
from Globals import Persistent

from Globals import MessageDialog
from DocumentTemplate.DT_Util import html_quote
import traceback, sys, os
from OFS.SimpleItem import Item
from Products.tandabuku.Bookmark import Bookmark
from OFS.Folder import Folder
import time
addForm = PageTemplateFile('zpt/addForm.zpt',globals())
#addForm = DTMLFile('dtml/addForm',globals())

def manage_addzBookmark(self, title='', url='', tags='', status='public',
			desc='',  REQUEST=None):
    """the add method"""
    id = str(time.time())
    ob = zBookmark(id, title, url, tags, status, desc)
    self._setObject(id,ob)
    if REQUEST is not None:
        return REQUEST.RESPONSE.redirect('manage_workspace')


class zBookmark(CatalogAware, Bookmark, Implicit, Persistent, RoleManager, Folder):
    """Bookmark."""

    meta_type = 'Bookmark'
    manage_options=(
              {'label' : 'Edit', 'action' : 'editBookmarkForm','help': ('XXX','edit.txt') },

           ) + Folder.manage_options[1:]

    _properties = ( 
			{'id':'title','type':'string','mode':'w'},
                        {'id':'url','type':'string','mode':'w'},
                        {'id':'tags','type':'tokens','mode':'w'},
                        {'id':'desc','type':'text','mode':'w'},
            )

    security=ClassSecurityInfo()
    security.declareProtected('Edit Bookmarks','editBookmarkForm')
    #editRatingForm = DTMLFile('dtml/editRatingForm',globals())
    editBookmarkForm = PageTemplateFile('zpt/zeditBookmarkForm.zpt',globals())

    def __init__(self, id, title='', url='', tags='', status='public', desc=''):
        """my init"""
        Bookmark.__init__(self, id, title, url, tags, status, desc)
        self.uid = getSecurityManager().getUser().getId()

    def getTags(self):
        """return list as strings sep by space"""
        return ' '.join(self.tags)

    security.declareProtected('Edit Bookmarks','manage_editzBookmark')
    def manage_editzBookmark(self, title, url, tags, status, desc, REQUEST=None):
        """edit """
        self.title = title
        self.url = url
        self.tags = tags.split()
	self.status = status
	self.desc = desc
        self.dateposted = time.ctime(time.time())
        self._p_changed = 1

        self.reindex_object()

        if REQUEST is not None:
            return REQUEST.RESPONSE.redirect('manage_workspace')

InitializeClass(zBookmark)


